﻿//----------------------------------------------------------------
// Desc: 
// Edit: ShowLong, http://blog.csdn.net/showlong
//
// Date Created: 2012-04-13
//
// Update Date : 
//
// Copyright (c) Fuel4D (http://www.fuel4d.com), All rights reserved.
//
//----------------------------------------------------------------
#pragma once


class IFFileObject : public IFPropObject
{
protected:
    explicit IFFileObject()
        :IFPropObject(eFP_Default)
        ,szFilenameW(0)
        ,szFilenameA(0)
        ,szExtnameW(0)
        ,szExtnameA(0)
    {
        FMemzero(szFilepathW, sizeof(szFilepathW));
        FMemzero(szFilepathA, sizeof(szFilepathA));
    }

public:
    // 设置文件路径
    FINLINE void SetFilepath (const NCHAR* path);
    FINLINE void SetFilepathW(const WCHAR* path);
    FINLINE void SetFilepathA(const ACHAR* path);
    // 获取文件路径
    FINLINE const NCHAR* const GetFilepath ();
    FINLINE const WCHAR* const GetFilepathW();
    FINLINE const ACHAR* const GetFilepathA();
    // 获取文件名
    FINLINE const NCHAR* const GetFilename ();
    FINLINE const WCHAR* const GetFilenameW();
    FINLINE const ACHAR* const GetFilenameA();
    // 获取扩展名
    FINLINE const NCHAR* const GetExtname ();
    FINLINE const WCHAR* const GetExtnameW();
    FINLINE const ACHAR* const GetExtnameA();

    // 相关标记状态函数
    FDECLARE_PROPERTY(Register, eFP_Register)
    FDECLARE_PROPERTY(FileResource, eFP_FileResource)
    FDECLARE_PROPERTY(DiySize, eFP_DiySize)
    FDECLARE_PROPERTY(Locking, eFP_Locking)
    FDECLARE_PROPERTY(ThreadCreate, eFP_ThreadCreate)
    FDECLARE_PROPERTY(Solidify, eFP_Solidify)
    FDECLARE_PROPERTY(Created, eFP_Created)
    FDECLARE_PROPERTY(CantCreate, eFP_CantCreate)

protected:
    const WCHAR* szFilenameW;
    const WCHAR* szExtnameW;
    WCHAR szFilepathW[MAX_PATH];
    const ACHAR* szFilenameA;
    const ACHAR* szExtnameA;
    ACHAR szFilepathA[MAX_PATH];
};

FINLINE void IFFileObject::SetFilepath (const NCHAR* path)
{
#ifdef UNICODE
    SetFilepathW(path);
#else
    SetFilepathA(path);
#endif
}
FINLINE void IFFileObject::SetFilepathW(const WCHAR* path)
{
    if (path && *path)
    {
        FStrcpyW(szFilepathW, path);
        FStrcpyA(szFilepathA, FStringA(path));

        szFilenameW = FFileNamePositionW(szFilepathW);
        szExtnameW = FFileExtPositionW(szFilenameW);
        szFilenameA = FFileNamePositionA(szFilepathA);
        szExtnameA = FFileExtPositionA(szFilenameA);
    }
    else
    {
        FMemzero(szFilepathW, sizeof(szFilepathW));
        szFilenameW = szFilepathW;
        szExtnameW = 0;
        FMemzero(szFilepathA, sizeof(szFilepathA));
        szFilenameA = szFilepathA;
        szExtnameA = 0;
    }
}
FINLINE void IFFileObject::SetFilepathA(const ACHAR* path)
{
    if (path && *path)
    {
        FStrcpyW(szFilepathW, FStringW(path));
        FStrcpyA(szFilepathA, path);

        szFilenameW = FFileNamePositionW(szFilepathW);
        szExtnameW = FFileExtPositionW(szFilenameW);
        szFilenameA = FFileNamePositionA(szFilepathA);
        szExtnameA = FFileExtPositionA(szFilenameA);
    }
    else
        SetFilepathW(0);
}
FINLINE const NCHAR* const IFFileObject::GetFilepath ()
{
#ifdef UNICODE
    return GetFilepathW();
#else
    return GetFilepathA();
#endif
}
FINLINE const WCHAR* const IFFileObject::GetFilepathW()
{
    return szFilepathW;
}
FINLINE const ACHAR* const IFFileObject::GetFilepathA()
{
    return szFilepathA;
}
FINLINE const NCHAR* const IFFileObject::GetFilename ()
{
#ifdef UNICODE
    return GetFilenameW();
#else
    return GetFilenameA();
#endif
}
FINLINE const WCHAR* const IFFileObject::GetFilenameW()
{
    return szFilenameW;
}
FINLINE const ACHAR* const IFFileObject::GetFilenameA()
{
    return szFilenameA;
}
FINLINE const NCHAR* const IFFileObject::GetExtname ()
{
#ifdef UNICODE
    return GetExtnameW();
#else
    return GetExtnameA();
#endif
}
FINLINE const WCHAR* const IFFileObject::GetExtnameW()
{
    return szExtnameW;
}
FINLINE const ACHAR* const IFFileObject::GetExtnameA()
{
    return szExtnameA;
}